//
//  MPTabBarController.m
//  MPOC
//
//  Created by DaVinci on 16/4/7.
//  Copyright © 2016年 DaVinci. All rights reserved.
//

#import "MPTabBarController.h"
#import "MPHomeController.h"
#import "MPDiscoveryController.h"
#import "MPTabBar.h"

@interface MPTabBarController ()

@end

@implementation MPTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self addChildControllers];
    
    MPTabBar *tab = [[MPTabBar alloc]init];
    
    
    
    
    [self setValue:tab forKey:@"tabBar"];
}



- (void)addChildControllers
{
    
    
    MPDiscoveryController *discovery = [[MPDiscoveryController alloc]init];
    [self addchildControllerWithTitle:@"首页" AndController:discovery imageName:@"tabbar_home"];
    
    MPHomeController *home = [[MPHomeController alloc]init];
    [self addchildControllerWithTitle:@"发现" AndController:home imageName:@"tabbar_profile"];
   
    
    
}

- (void)addchildControllerWithTitle:(NSString *)title AndController:(UIViewController *)controller imageName:(NSString *)imageName{

    controller.tabBarItem.title = title;
    controller.navigationItem.title = title;
    controller.tabBarItem.image = [UIImage imageNamed:imageName];
    
    NSString *selected = [imageName stringByAppendingString:@"_selected"];
    
    NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];
    [controller.tabBarItem setTitleTextAttributes:dict forState:UIControlStateSelected];
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:selected] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:controller];
    
    [self addChildViewController:nav];

}
@end
